package com.jjiang.bbmall.search.controller;

import com.jjiang.bbmall.search.service.ProductSaveService;
import com.jjiang.common.exception.BizCodeEnumerate;
import com.jjiang.common.to.es.SkuEsModel;
import com.jjiang.common.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/search/save")
@RestController
@Slf4j
public class ElasticSaveController {

    @Autowired
    ProductSaveService productSaveService;

    /**
     * 上架商品
     *
     * @param skuEsModels
     * @return
     */
    @PostMapping("/product")
    public R productStatusUp(@RequestBody List<SkuEsModel> skuEsModels) {
        boolean r = productSaveService.productStatusUp(skuEsModels);

        if (r) {
            return R.ok();
        } else {
            log.error("ElasticSaveController上架错误");
            return R.error(BizCodeEnumerate.PRODUCT_UP_EXCEPTION.getCode(), BizCodeEnumerate.PRODUCT_UP_EXCEPTION.getMsg());
        }
    }

}
